﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace automatic
{
    public partial class frmMatic : Form
    {
        public frmMatic()
        {
            InitializeComponent();
        }

        int a, b;
        string op;
        int result;
        Random rnd = new Random();

        private void frmMatic_Load(object sender, EventArgs e)
        {
            label5.Text = "默认5s";
            label6.Text = "";
            matic();
            
        }

        double ccount;
        private void btnOk_Click(object sender, EventArgs e)
        {
            matic();
            ccount++;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (chkBox1.Checked)
            {
                matic();
                ccount++;
            }
        }
        //出题
        void matic() 
        {
            
            a = rnd.Next(9) + 1;
            b = rnd.Next(9) + 1;
            op = "+";
            result = a + b;
            if (radBtn2.Checked)
            {
                op = "+";
                a = rnd.Next(19) + 1;
                b = rnd.Next(19) + 1;
                result = a + b;
            }
            else if (radBtn3.Checked)
            {
                op = "*";
                result = a * b;
            }
            label1.Text = a.ToString();
            label3.Text = b.ToString();
            label2.Text = op;
            textBox1.Text = "";
            textBox1.Enabled = true;
            textBox1.Focus();
            textBox1.Font = new Font("宋体", 30);              
            textBox1.BackColor = Color.White;
        
        }
        //难易程度判断
       void level()
       {
           {
               switch ((a + b) / 10)
               {
                   case 0:
                       textBox1.Text = "☆";
                       break;
                   case 1:
                       textBox1.Text = "☆☆";
                       break;
                   default:
                       textBox1.Text = "☆☆☆";
                       break;
               }

           }
           
       }
       double sumcout,cocount,falcount;
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
             string str = textBox1.Text.Trim();
             
            if (e.KeyCode == Keys.Enter && str == "")
            {
                MessageBox.Show("请输入答案", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (e.KeyCode == Keys.Enter && str != "")
            {           
                double d = double.Parse(str);
                if (d == result)
                {
                    textBox1.BackColor = Color.SeaGreen;
                    textBox1.Font = new Font("宋体", 12);
                    level();
                    textBox1.Text +=  Environment.NewLine + "正确"+result ;
                    cocount++;
                }
                else
                {
                    textBox1.BackColor = Color.Red;
                    textBox1.Font = new Font("宋体", 12);
                    level();
                    textBox1.Text += Environment.NewLine+"错误" + Environment.NewLine + "正确答案:" + result;
                    falcount++;
                }
                textBox1.Enabled = false;
                sumcout++;
            }
              
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (chkBox2.Checked) 
            {
                textBox1.Font = new Font("宋体", 12);
                level();
                textBox1.Text +=Environment.NewLine+"正确答案："+ result;
            }
        }

        int count = 0;
        private void btnQ_Click(object sender, EventArgs e)
        {
            count++;
            switch (count)
            {
                case 1:
                    timer1.Interval = 4000;
                    label5.Text = "快进1X";
                    break;
                case 2:
                    timer1.Interval = 3000;
                    label5.Text = "快进2X";
                    break;
                case 3:
                    timer1.Interval = 2000;
                    label5.Text = "快进3X";
                    break;
                default:
                    timer1.Interval = 5000;
                    count = 0;
                    label5.Text = "默认5s";
                    break;
            }
        }

        int icount = 0;
        private void btnL_Click(object sender, EventArgs e)
        {
             icount++;
             switch (icount)
             {
                 case 1:
                     timer1.Interval = 6000;
                     label5.Text = "慢进1X";
                     break;
                 case 2:
                     timer1.Interval = 7000;
                     label5.Text = "慢进2X";
                     break;
                 case 3:
                     timer1.Interval = 8000;
                     label5.Text = "慢进3X";
                     break;
                 default:
                     timer1.Interval = 5000;
                     label5.Text = "默认5s";
                     icount = 0;
                     break;
             }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (sumcout != 0)
            {
                label6.Text = "出题：" + (ccount + 1) + " 道，" + "回答了" + sumcout.ToString() + "道题，"
               + "正确" + cocount + "道，" + "错误" + falcount + "道，" + "正确率" + ((cocount / sumcout) * 100).ToString("0.00") + "%";
            }
            else
            {
                label6.Text = "出题：" + (ccount + 1) + " 道，" + "未做答";
            }
            
        }
    }
}
